import {State, StateMachine} from "../stateMachine";
import {Conversation, sentence} from "./conversation";

export class ConversationMachine extends StateMachine{
    public static istalking:boolean=false;
    public state:string="none";

    public currentNormal:number=0;
    public currentKeyClue:number=0;

    public normalDialogs:sentence[][];
    public keyClueDialogs:sentence[][];

    public conversation:Conversation;

    /*
* 切换下一个日常对话
* */
    public nextNormal(){
        if(this.currentNormal<this.normalDialogs.length-1){
            this.currentNormal++;
        }
    }

    public nextKeyClue(){
        if(this.currentKeyClue<this.keyClueDialogs.length-1){
            this.currentKeyClue++;
        }
    }
}

//这里是愉快的日常~
export class ConversationNormalState extends State{

    private conversationMachine:ConversationMachine;

    constructor(machine:ConversationMachine){
        super();
        this.conversationMachine=machine;
    }
    
    onEnter() {
        ConversationMachine.istalking=true;
        this.conversationMachine.state="normal";
        const conversation=this.conversationMachine.conversation;

        conversation.currentSentence=0;

        console.log("convert to normal");
        conversation.sentences=this.conversationMachine.normalDialogs[this.conversationMachine.currentNormal];
        conversation.beginConversation();

        ConversationMachine.istalking=false;
    }

    onExit() {

        // if(this.conversationMachine.currentNormal<this.conversationMachine.normalDialogs.length-1){
        //     this.conversationMachine.currentNormal++;
        // }
    }
}

//关键剧情状态
export class ConversationKeyClueState extends State{
    private conversationMachine:ConversationMachine;

    constructor(machine:ConversationMachine){
        super();
        this.conversationMachine=machine;
    }
    
    onEnter() {
        ConversationMachine.istalking=true;
        this.conversationMachine.state="keyClue";
        if(this.conversationMachine.currentKeyClue<this.conversationMachine.keyClueDialogs.length){
            const conversation=this.conversationMachine.conversation;

            conversation.currentSentence=0;

            console.log("convert to key clue");
            conversation.sentences=this.conversationMachine.keyClueDialogs[this.conversationMachine.currentKeyClue];
            conversation.beginConversation();

            ConversationMachine.istalking=false;
            this.conversationMachine.state="normal";
        }
    }

    onExit() {

        // if(this.conversationMachine.currentKeyClue<this.conversationMachine.keyClueDialogs.length){
        //     this.conversationMachine.currentKeyClue++;
        // }
    }
    
}

//获取物品的对话框
export class ConversationGetItemState extends State{

    private conversationMachine:ConversationMachine;

    constructor(machine:ConversationMachine){
        super();
        this.conversationMachine=machine;
    }
    
    onEnter() {

    }    
    
    onExit() {
    }

    
}
